/**
 * @Copyright ®2015 Sinosoft Co. Ltd. All rights reserved.
 * 项目名称 : 网站服务平台
 * 创建日期 : 2016-10-24
 * 修改历史 :
 * 1. [2016-10-24]创建文件 by chenxin
 */
package com.gavinwind.inspay.common.logger;

import com.gavinwind.inspay.common.config.ENUM_REPORT_TYPE;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.WeakHashMap;

/**
 * 【平台日志基础类】
 * @author Gavin
 * @date 2016-10-24 上午11:13 
 * @version V1.0
 * @description 使用者需要自行配置Log的配置文件,结合工具类使用
 */
public class PlatformLogger{
    /** 默认日志工具实例 */
    private Logger logger;
    /** 日志工具实例容器 */
    private Map<String,Logger> loggers = new WeakHashMap<String,Logger>();

    public static PlatformLogger getLogger(Class cClass){
        PlatformLogger tLogger = new PlatformLogger(cClass);
        return tLogger;
    }

    private PlatformLogger(Class logClass){
        logger = loggers.get("Normal");
        if(logger == null){
            Logger tLogger  = LoggerFactory.getLogger(logClass);
            loggers.put("Normal",tLogger);
            logger = tLogger;
        }
    }

    public void info(String cTraceInfo){
        logger.info(cTraceInfo);
    }
    public void info(String cTraceInfo,String param){
        logger.info(cTraceInfo,param);
    }
    public void debug(String cTraceInfo){
        logger.debug(cTraceInfo);
    }

    public void error(String cTraceInfo){
        logger.error(cTraceInfo);
    }

    public void warn(String cTraceInfo){
        logger.warn(cTraceInfo);
    }

    public void error(String cTraceInfo,Throwable e){
        logger.error(cTraceInfo,e);
    }

    public void error(String cTraceInfo,Object e){
        logger.error(cTraceInfo,e);
    }
    public void trace(String cTraceInfo){
        logger.trace(cTraceInfo);
    }


    /**
     * 报文日志打印类
     * @description 根据ENUM_REPORT_TYPE中的配置信息,将日志输出到指定Appender中
     * @param reportType
     * @param cReportInfo
     */
    public void report(ENUM_REPORT_TYPE reportType, String cReportInfo){
        String tReportType =  reportType.getReportType();
        String tAppenderName = reportType.getAppenderName();
        Logger tLogger  =  loggers.get(tReportType);
        if(tLogger == null){
            tLogger = LoggerFactory.getLogger(tAppenderName);
        }
        tLogger.info("【"+tReportType+"】\n" + cReportInfo);
    }

}
